<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    {{include '../shared/_header'}}
</head>
<body>
<div class="weui-toptips weui-toptips_warn js_tooltips weui-icon-warn" id="errTip" style="display: none;">错误提示</div>
<div class="weui-toptips weui-toptips_warn weui-toptips_success weui-icon-success js_tooltips" id="successTip" style="display: none;">注册成功</div>
	<div class="weui-tab">
		<div class="weui-tab__panel">
		    <div class="weui-cells weui-cells_form">
		        <div class="weui-cell">
		            <div class="weui-cell__hd">
		                <label class="weui-label">手机号</label>
		            </div>
		            <div class="weui-cell__bd">
		                <input type="number" id="txtMobile" class="weui-input" required placeholder="请输入手机号">
		            </div>
		        </div>
		        <div class="weui-cell">
		            <div class="weui-cell__hd">
		                <label class="weui-label">密码</label>
		            </div>
		            <div class="weui-cell__bd">
		                <input type="password" id="txtPwd" class="weui-input" required placeholder="请输入密码">
		            </div>
		        </div>
			    <div class="weui-btn-area">
			        <div class="weui-btn weui-btn_primary" id="btnLogin">登录</div>
			    </div>
			    <a href="/reg" class="weui-footer__link page__desc">注册</a>
			</div>
		</div>
		{{include '../shared/_footer_nav'}}
	 </div>

    {{include '../shared/_bottom'}}
    <script>
		var regMobile = /^1[3857]{1}\d{9}$/
		$('#btnLogin').click(function(){
			var mobile = $('#txtMobile').val().trim()
			var pwd = $('#txtPwd').val().trim()
		    if(!regMobile.test(mobile)){
		        showTip("errTip","手机号码格式错误")
		        return false
		    }
		    if(pwd){
		    	if(pwd.length<6){
		    		showTip("errTip","密码不能小于六位")
		    		return false
		    	}
		    }
		    else{
		    	showTip("errTip","密码不能为空")
		    	return false
		    }
		    $.ajax({
		    	url:'/login',
		    	method:'post',
		    	data:{mobile:mobile,pwd:pwd},
		    	error:function(err){
		    		console.log(err)
		    	},
		    	success:function(res){
		    		if(res.status=="y"){
		    			// showTip("successTip",res.msg)
                        window.location.href = "/usercenter" //登录成功后跳转到用户中心
		    		}
		    		else{
		    			showTip("errTip",res.msg)
		    		}
		    	}
		    })
		})
		function showTip(tag,msg){
		    var $tip = $("#"+tag)
		    $tip.text(msg)
		    $tip.show()
		    setTimeout(function(){
		        $tip.hide()
		    },3000)
		}
    </script>
</body>
</html>